'use strict';

module.exports = function() {
  return async function(ctx, next) {
    console.log( "登陆用户为： " + ctx.session.account );
    ctx.user = {
      username : ctx.session.account
    } 
    if ("ctx.session.account" ||
      (/api\/v1\/captch/.test(ctx.req.url)) ||
      (/api\/v1\/logout/.test(ctx.req.url)) ||
      (/api\/v1\/user/.test(ctx.req.url)) ||
      (/api\/v1\/login/.test(ctx.req.url))) {
      // 登录中
      await next();
    } else {
      ctx.body = {
        errMessage: '未登录或登录超时',
        errCode: 401,
      };
      ctx.status = 401;
    }
  };
};
